package kassiopeia.commons.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import com.thoughtworks.xstream.annotations.XStreamAlias;

@Embeddable
@XStreamAlias("coordinates")
public final class Coordinates implements Serializable {

    private static final long serialVersionUID = -1869551907966401577L;

    @Column(nullable = false)
    private String pluginId;

    @Column(nullable = false)
    private String groupId;

    @Column(nullable = false)
    private String version;

    public Coordinates() {}

    public Coordinates(String pluginId, String groupId, String version) {
        this.pluginId = pluginId;
        this.groupId = groupId;
        this.version = version;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public void setPluginId(String pluginId) {
        this.pluginId = pluginId;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getPluginId() {
        return pluginId;
    }

    public String getGroupId() {
        return groupId;
    }

    public String getVersion() {
        return version;
    }

    @Override
    public String toString() {
        return "[" + pluginId + "," + groupId + "," + version + "]";
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(11, 31, this);
    }

    @Override
    public boolean equals(Object obj) {
        if((obj == null) || !(obj instanceof Coordinates)) { return false; }
        if(obj == this) { return true; }

        Coordinates other = (Coordinates) obj;

        return EqualsBuilder.reflectionEquals(this, other);
    }
}
